<?xml version="1.0" encoding="UTF-8"?>

<!--
    Document   : sqlibench_xsl1.xsl
    Created on : July 12, 2008, 9:36 PM
    Author     : Administrator
    Description:
        Purpose of transformation follows.
-->

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    
    <xsl:param name="title">SQLiBENCH XSL Transformation 1</xsl:param>
    
    <xsl:output method="html"/>

    <!-- TODO customize transformation rules 
         syntax recommendation http://www.w3.org/TR/xslt 
    -->
    <xsl:template match="/sqlibench">
        <html>
            <head>
                <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
                <title><xsl:value-of select="$title"/></title>
                <!--
                <link href="style.css" rel="stylesheet" type="text/css"/>
                -->
            </head>
            <body>

            <xsl:call-template name="recursivePrint">
                <xsl:with-param name="criteriaItemList" select="/sqlibench"/>
            </xsl:call-template>
            </body>
        </html>
    </xsl:template>

    <!-- recursive function definition -->
    <xsl:template name="recursivePrint">
      <xsl:param name="criteriaItemList"/>
      
      <!-- stopping criteria, when the list is empty stop processing -->
      <xsl:if test="$criteriaItemList">
        <ol>
          <!-- for each child of the current list print the label and try to go deeper -->
          <xsl:for-each select="$criteriaItemList/child::*">
            <li>
               <xsl:choose>
                   <!-- 
                    if the children of the context node are text nodes, 
                    that means we are at the leaf
                   -->
                   <xsl:when test="self::*/child::text()">
                        <!-- print the label and then the it's content (text) -->
                        <xsl:value-of select="self::*/@label"/>
                        <br/>
                        <xsl:value-of select="self::*/child::text()"/>
                  </xsl:when>
                  <!-- the context node is not a leaf, so print it's label and try to go deeper -->
                   <xsl:otherwise>
                       <xsl:value-of select="self::*/@label"/>                           
                       <!-- recursively call the function with the context node in the list -->
                        <xsl:call-template name="recursivePrint">
                            <xsl:with-param name="criteriaItemList" select="self::*"/>
                        </xsl:call-template>                       
                   </xsl:otherwise>
               </xsl:choose>
            </li>
          </xsl:for-each>
        </ol>        
      </xsl:if>
    </xsl:template>

</xsl:stylesheet>
